package main.www.wonderfuldata.PreparedStatement;

import main.www.wonderfuldata.bean.Person;
import main.www.wonderfuldata.bean.User2;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 针对Customers表的查询操作
 */
public class CustomerForQuery {


    public void testQuery1() throws Exception {


        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;
        //设置为空防止空指针异常


        conn = JDBCUtils.getConnection();

        String sql = "select id,name,password,email from Teacher where id =1";
        ps = conn.prepareStatement(sql);

        //执行，返回结果集
        resultSet = ps.executeQuery();


        if (resultSet.next()) {
            //获取字段集
            int id = resultSet.getInt(1);
            String name = resultSet.getString(2);
            String password = resultSet.getString(3);
            String email = resultSet.getString(4);
            //2:  Object[] data = new Object[id,name,email];


            //3： 对象实现集合
            Person person = new Person(id,name,password,email);
            System.out.println(person);

        }

        //  关闭资源
        JDBCUtils.closeResource(conn,ps,resultSet);



    }


    //首页的login登陆效果
    //User


    public void login() throws Exception {


        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;
        //设置为空防止空指针异常


        conn = JDBCUtils.getConnection();

        String sql = "select idUser,name,password  from User2 where idUser =1";
        ps = conn.prepareStatement(sql);

        //执行，返回结果集
        resultSet = ps.executeQuery();


        if (resultSet.next()) {
            //获取字段集
            int idUser = resultSet.getInt(1);
            String name = resultSet.getString(2);
            String password = resultSet.getString(3);
            //String email = resultSet.getString(4);
            //2:  Object[] data = new Object[id,name,email];


            //3： 对象实现集合
            //Person person = new Person(id,name,password,email);
            //System.out.println(person);
            User2 user = new User2(name,idUser,password);
            System.out.println(user);


        }

        //  关闭资源
        JDBCUtils.closeResource(conn,ps,resultSet);



    }
}
